package testdemo.dao.impl;

import edu.nf.SQLExecutor;
import edu.nf.beans.annotations.Component;
import edu.nf.handler.MapListHandler;
import testdemo.dao.NoticeDao;
import testdemo.model.Notice;
import testdemo.utils.ConnUtil;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Component("NoticeDao")
public class NoticeDaoImpl implements NoticeDao{
    private SQLExecutor sq = null;
    @Override
    public List<Map<String, Object>> getAllnotice() {
        String sql = "select * from t_notice";
        sq  = new SQLExecutor(ConnUtil.getConnection());
        MapListHandler handler  = new MapListHandler();
        List<Map<String,Object>> list = sq.executeQuery(sql,handler);
        return list;
    }

    @Override
    public void deleteNotice(int id) {
     String sql ="delete from t_notice where id = ?";
     sq = new SQLExecutor(ConnUtil.getConnection());
     sq.executeUpdate(sql,id);
    }

    @Override
    public void updateNotice(int id) {
     String sql = "select from where id=?";
     sq = new SQLExecutor(ConnUtil.getConnection());
     sq.executeUpdate(sql,id);
    }

    @Override
    public void addNotice(Integer id, String title, String content, Date time) {
        String sql="insert into t_notice(content,title) values(?,?)";
        sq = new SQLExecutor(ConnUtil.getConnection());
        sq.executeUpdate(sql,id,title,content,time);
    }
}
